package aom.ju.ss.view.user

import android.view.View
import aom.ju.ss.R
import aom.ju.ss.databinding.SetPassActivityBinding
import aom.ju.ss.lpInterface.TitleDialogInterface
import aom.ju.ss.mode.LpKey
import aom.ju.ss.mode.UserInfo
import aom.ju.ss.utils.*
import aom.ju.ss.utils.http.LP_API
import aom.ju.ss.utils.http.OKHttpUtils
import aom.ju.ss.view.base.BaseActivity
import aom.ju.ss.view.dialog.TitleDialog
import com.google.gson.Gson

class SetPassActivity : BaseActivity() {
    /**
     * 密码类型  data 1设置登录密码  2 设置支付密码 2忘记支付密码
     */
    val arrts = arrayOf("设置登录密码", "设置支付密码", "忘记密码")
    private lateinit var binding: SetPassActivityBinding
    override fun init() {
        binding = viewBinding as SetPassActivityBinding
        binding.phone = UserInfo.userInfo?.phone
        binding.titleView11.title.text = arrts[data.toInt()]
        binding.send.setOnClickListener {
            sendCode(binding.pnum, binding.send)
        }
        binding.ok.setOnClickListener {
            LogUtils.e(binding.code.isCode)
            LogUtils.e(binding.pas.passWordeq(binding.pasTwo))
            if (binding.code.isCode && binding.pas.passWordeq(binding.pasTwo)) {
                val password = encrypt(binding.pas.text.toString())

                LogUtils.e("passtype="+data)
                OKHttpUtils(activity)
                    .SetApiUrl(LP_API.set_pass)
                    .SetKey("password", "pass_type", "code")
                    .SetValue(password, data, binding.code.text.toString())
                    .POST(this)
            }

        }

    }

    override fun ok(jsonString: String, httpTY: String) {
        super.ok(jsonString, httpTY)
        UserInfo.userInfo
        TitleDialog.showMsg(activity, "设置成功", object : TitleDialogInterface {
            override fun ok(view: View?, IsDetermine: Boolean) {
                UserInfo.userInfo!!.isset_pay_password = "1"
                SpUtils.putString(LpKey.USER_INFO, Gson().toJson(UserInfo.userInfo))
                finish()

            }

        })
    }

    override fun error(e: String, jsonString: String, httpTY: String) {
        super.error(e, jsonString, httpTY)
        e.show
    }

    override val lay: Int = R.layout.set_pass_activity
}